package com.shuzixiangcun.controller.admin;

import com.shuzixiangcun.entity.Villages;

import com.shuzixiangcun.service.admin.VillagesServiceImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 村庄表(Villages)表控制层
 *
 * @author makejava
 * @since 2024-06-24 08:26:17
 */
@RestController
@RequestMapping("admin/villages")
public class VillagesController {
    /**
     * 服务对象
     */
    @Resource
    private VillagesServiceImpl villagesService;



    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Villages> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.villagesService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param villages 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Villages> add(Villages villages) {
        return ResponseEntity.ok(this.villagesService.insert(villages));
    }

    /**
     * 编辑数据
     *
     * @param villages 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Villages> edit(Villages villages) {
        return ResponseEntity.ok(this.villagesService.update(villages));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.villagesService.deleteById(id));
    }

}

